<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<link rel="stylesheet" href="../../css/index.css">
		<link rel="stylesheet" href="../../layui/css/layui.css" />
<title>添加规则</title>
</head>
<body>

	<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
      <label class="layui-form-label">标题</label>
      <div class="layui-input-inline">
        <input type="text" id="rulename" name="rulename" lay-verify="required" placeholder="标题不能为空" autocomplete="off" class="layui-input">
      </div>
    </div>
    
     <div class="layui-form-item">
      <label class="layui-form-label">备注</label>
      <div class="layui-input-inline">
        <input type="text" id="note" name="note" placeholder="请填写备注"  class="layui-input">
      </div>
    </div>
    
     <div class="layui-form-item" style="margin-left:20px;">
     	<textarea id="rulececontent" style="display: none;"></textarea>
     
     </div>
  	
    <div class="layui-form-item layui-hide">
      <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认添加">
      <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
    </div>
  </div>
	
	
</body>

<script type="text/javascript" src="../../layui/layui.all.js" charset="utf-8"></script>
<script>
layui.use(['form','layedit','jquery'], function(){
  
  var layedit = layui.layedit,$ = layui.jquery, form = layui.form;
  
	  layedit.set({
	  uploadImage: {
	    url: '' //接口url
	    ,type: '' //默认post
	  }
	});
	//注意：layedit.set 一定要放在 build 前面，否则配置全局接口将无效。
	layedit.build('rulececontent'); //建立编辑器
  
  	
  
  	//监听点击提交
    form.on('submit(layuiadmin-app-form-submit)', function(data){
      var field = data.field; //获取提交的字段
      var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引 

		
		
		    var rulename = $("#rulename").val();
		    var note = $("#note").val();
			var rulececontent = layedit.getContent(index);//获取文本编辑器的内容
		
			var obj = {
				"rulename":rulename,
				"note":note,
				"rulececontent":rulececontent
			};
			var param = JSON.stringify(obj);
			//alert(param)
			$.ajax({
				url:"../../rulemana/addrule",
				type:"POST",
				data:param,
				dataType : "json",
				xhrFields :{
					withCredentials: true
				},
				contentType:'application/json;charset=UTF-8',
				success:function(e){
					if(e.code == 0){
						layer.msg("添加成功",{icon:6}); 
					}else{
						layer.msg("添加失敗",{icon:5});
						return;
					}
					
					setTimeout(function(){
						parent.layer.close(index); //再执行关闭 
						parent.layui.table.reload('rule'); //重载表格
      					
					},1*1000)
					
				},
				error:function(e){
					layer.msg("添加失敗",{icon:5});
					
				}
			})
      	return false;
    });
  
  
  
});
</script>

</html>